package com.springcloud.consumer.service.api;

import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.http.ResponseEntity;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestMethod;
import org.springframework.web.bind.annotation.RestController;
import org.springframework.web.client.RestTemplate;

@RestController
public class ConsumerController {

    @Autowired
    private RestTemplate restTemplate;

    @RequestMapping(value = "/getByProivide",method = {RequestMethod.GET})
    public String getProvide(){
        //通过provide-server服务名寻找服务
        //@LoadBalanced注解是用过服务名寻找地址
        ResponseEntity<String> entity = restTemplate.getForEntity("http://provide-server/provide", String.class);
        String body = entity.getBody();
        System.out.println("body: "+entity);

        return "调用了Provide body内容："+entity;
    }

}
